#include "widget.h"
#include "ui_widget.h"
#include<QMessageBox>
#include <QDebug>
#include <QHostAddress>


Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    m_pSocket=NULL;
}

Widget::~Widget()
{
    delete ui;
}

void Widget::InitClientWidget(){

    qDebug()<<"Widget::InitClientWIdget start";
    if(NULL!=m_pSocket){
        return;
    }
    m_pSocket=new QTcpSocket(this);
    connect(m_pSocket,SIGNAL(readyRead()),this,SLOT(OnReadyRead()));
    qDebug()<<"void Widget::InitClientWidget() end";
}

void Widget::on_reset_clicked()
{
    if(ui->lineEdit->text()!="" || ui->lineEdit_2->text()!="")
    {
        ui->lineEdit->setText("");
        ui->lineEdit_2->setText("");
    }
}

void Widget::on_login_clicked()
{
    if(ui->lineEdit->text() == "admin" && ui->lineEdit_2->text()=="123456")
    {
        Form *f1=new Form();
        f1->show();
        this->hide();
        qDebug()<<"Widget::on_connectBtn_clicked start";
        if(NULL==m_pSocket){
            return;
        }

        qDebug()<<"void Widget::on_connectBtn_clicked() end";
    }else{
        QMessageBox::warning(this,"警告","您的输入无效，请重新输入");
    }

}

void Widget::on_exit_clicked()
{
    this->close();
}

void Widget::OnReadyRead()
{

    qDebug()<<"Widget::OnReadyRead start";

    QByteArray arr=m_pSocket->readAll();
    qDebug()<<arr;
    qDebug()<<"Widget::OnReadyRead end";
}
